package net.htjs.juc.chapter06.accountcas;

import java.util.ArrayList;
import java.util.List;

public interface Account {

    Integer getBalance();

    public void withdraw(Integer amount);

    static void demo(Account account) {
        List<Thread> threads = new ArrayList<>();
        for(int i = 0; i < 1000; i++) {
            threads.add(new Thread(() -> account.withdraw(10)));
        }
        long start = System.currentTimeMillis();
        threads.forEach(Thread::start);
        threads.forEach(thread -> {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        long end = System.currentTimeMillis();
        System.out.println(account.getBalance() + " cost: " + (end - start));
    }

}
